// // pages/category/category.js
import {
  request
} from "../../request/index"
Page({
  data: {
    //左侧数据
    leftlist: [],
    //右侧数据
    rightlist: [],
    //所有数据
    data: [],
    //当前激活的下标
    currentTarget: 0,
    //右侧内容滚动条距离顶部的距离
    scrollTop: 0,
  },

  onLoad: function () {
    this.getcatelist()
  },

  getcatelist() {
    request({
      url: '/categories'
    }).then(res => {
      console.log(res);
      let leftlist = res.map(item => item.cat_name)
      console.log(leftlist);

      let rightlist = res[0].children
      this.setData({
        leftlist,
        rightlist,
        data: res
      })
    })
  },
  handleItemTap(e) {
    let {
      index
    } = e.currentTarget.dataset;
    let rightlist = this.data.data[index].children;
    this.setData({
      currentTarget: index,
      rightlist,
      scrollTop: 0
    })
  }
})